<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/element.css">
</head>
<body>
<div id="app">
    <#include "/include/daohang.html">
    <el-container>
        <el-header>
            <div style="padding: 10px;height: 50px">
                <el-form :model="searchform"  label-width="100px" class="demo-ruleForm">
                    <el-row>
                        <el-col :span="7">
                            <el-form-item label="搜索项1" >
                                <el-input v-model="searchform.item1" placeholder="请输入搜索项1"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="搜索项2" >
                                <el-input v-model="searchform.item2" placeholder="请输入搜索项2"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="搜索项3" >
                                <el-input v-model="searchform.item3" placeholder="请输入搜索项3"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="3">
                            <div align="center">
                                <el-button type="primary" @click="searchclick">搜索</el-button>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </el-header>
        <el-container>
            <el-aside width="15%">
                侧边栏
            </el-aside>
            <el-main>
                <div style="padding-bottom: 10px">
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-edit" @click="add">添加</el-button>
                        <el-button type="primary" icon="el-icon-share"  @click="share_drawer = true"></el-button>
                        <el-button type="primary" icon="el-icon-share"></el-button>
                        <el-button type="primary" icon="el-icon-delete"></el-button>
                    </el-button-group>
                </div>
                <template>
                    <el-table
                            :data="tableList"
                            stripe
                            @selection-change="handleSelectionChange"
                            style="width: 100%;min-height: 500px">
                        <el-table-column
                                type="selection"
                                width="55">
                        </el-table-column>
                        <el-table-column
                                prop="title"
                                :show-overflow-tooltip="true"
                                label="标题"
                                width="250">
                        </el-table-column>
                        <el-table-column
                                prop="createTime"
                                width="200"
                                label="创建时间">
                        </el-table-column>
                        <el-table-column
                                label="操作"
                                width="200">
                            <template slot-scope="scope">
                                <el-button @click="update(scope.row)" type="text" size="small">编辑</el-button>
                                <el-button type="text" @click="delete(scope.row.id)" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </template>

                <el-divider></el-divider>

                <el-pagination
                        background
                        @current-change="handleCurrentChange"
                        :page-sizes="[10,50,100,150,200,250,300]"
                        :page-size="size"
                        layout="total,sizes,prev, pager, next,jumper"
                        :total="total">
                </el-pagination>
            </el-main>
        </el-container>
    </el-container>


    <!-- 抽屉        -->
    <el-drawer title="我是标题" :visible.sync="share_drawer" :with-header="false">
        <span>这是抽屉</span>
    </el-drawer>


    <!-- 添加面板        -->
    <el-dialog title="添加面板" :visible.sync="dialogFormVisible_add">


        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible_add = false">取 消</el-button>
            <el-button type="primary" @click="submit_add">确 定</el-button>
        </div>
    </el-dialog>

    <!-- 编辑面板        -->
    <el-dialog title="编辑面板" :visible.sync="dialogFormVisible_update">


        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible_update = false">取 消</el-button>
            <el-button type="primary" @click="submit_update">确 定</el-button>
        </div>
    </el-dialog>
</div>
<#include "/include/commonjs.html">
<script>
    var Main = {
        extends: global,
        data() {
            return {
                share_drawer:false,//抽屉
                dialogFormVisible_add:false, //添加面板
                dialogFormVisible_update:false, //编辑面板
                activeIndex2: '1', //导航默认选中
                searchform:{

                },
                tableList:[], //表格数据
                total:0, // 条数
                size:10,
                multipleSelection:[], //多选,
                pageNum:1
            }
        },
        created(){
            this.getlist(1)
        },
        methods: {
            //搜索点击
            searchclick(){
                this.getlist(this.pageNum);
            },
            //分页点击
            handleCurrentChange(val){
                this.pageNum=val;
              this.getlist(this.pageNum);
            },
            //打开更新
            update(val){
                this.dialogFormVisible_update=true;
            },
            //确认更新
            submit_update(){
                this.$message({
                    showClose: true,
                    message: '确认更新成功',
                    type: 'success'
                });
                this.dialogFormVisible_update=false;
            },
            //添加
            add(){
                this.dialogFormVisible_add=true;
            },
            //添加确定
            submit_add(){
                this.$message({
                    showClose: true,
                    message: '确认添加成功',
                    type: 'success'
                });
                this.dialogFormVisible_add=false;
            },
            //删除
            delete(val){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    api.POST('/deleteurl',{'id':val},(result)=> {
                        if(result.code==0){
                            this.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            local.reload();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            getlist(val){
                this.searchform.pageNum=val;
                this.searchform.pageSize=this.size;
                api.GET('/url',this.searchform,(res)=>{
                    if(res.code===0){
                        this.tableList=res.data.records;
                        this.total=res.data.total;
                    }
                })
            },
            //多选
            handleSelectionChange(val){
                this.multipleSelection = val;
            },
            locationfref(href){
                window.open(href);
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            },

        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')

    function keyDown() {
        var keycode = event.keyCode;
        var realkey = String.fromCharCode(event.keyCode);
        if(keycode==13){
            $("#search-btn").click();
        }
        // alert("按键码: " + keycode + " 字符: "+ realkey);

    }
    document.onkeydown = keyDown;
</script>
</body>
</html>